module window

import webview
import config

// 窗口hint
fn hint_val(h string) webview.Hint {
	match h {
		'auto' {
			return .@none
		}
		'fixed' {
			return .fixed
		}
		'min' {
			return .min
		}
		'max' {
			return .max
		}
		else {
			return .@none
		}
	}
}

// 创建webview
pub fn create(win config.Win) &webview.Webview {
	wv := webview.create(debug: win.debug)
	// 设置窗口图标
    wv.set_icon(win.icon) or {
        error('failed to set the icon: ${err}')
    }
    // 设置窗口标题
    wv.set_title(win.title)
    // 设置窗口大小
    wv.set_size(win.width, win.height, hint_val(win.hint))
	return wv
}